package com.twu.biblioteca;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class BibliotecaApp {

    public static void main(String[] args) {

        new BibliotecaApp().startApp();

    }

    private void startApp() {
        PrintStream outPut = System.out;
        new WelcomeMessenger(outPut).printMessage();
        ArrayList<Book> bookList = prepareBookList();
        ArrayList<Movie> movieList = prepareMovieList();
        MenuGenerator mainMenu;
        mainMenu = prepareMainMenu(bookList, movieList, outPut);
        mainMenu.generateMenu();
        new InputParser(new InputSeeker(), mainMenu, outPut).parse();

    }

    private MenuGenerator prepareMainMenu(ArrayList<Book> list,ArrayList<Movie> movieList, PrintStream out) {
        InputSeeker in = new InputSeeker();
        MenuGenerator menu = new MenuGenerator(out);
        menu.addItem(new MenuOption(1, new BookListGenerator(list, out), "List all books"));
        menu.addItem(new MenuOption(2,new MovieListGenerator(movieList,out),"List all Movies"));
        menu.addItem(new MenuOption(3, new Login(out, in, prepareUserList(), new UserMenuComposer(list, out, in,movieList)), "Login"));
        return menu;
    }

    private Map<String, User> prepareUserList() {
        Map<String, User> userList = new HashMap<String, User>();
        userList.put("111-1111", new User("111-1111", "abcd", "Sam", "sam@twu.com", 123456));
        userList.put("111-1112", new User("111-1112", "abcd", "John", "john@twu.com", 123456));
        return userList;

    }


    private ArrayList<Book> prepareBookList() {
        ArrayList<Book> bookList = new ArrayList<Book>();
        bookList.add(new Book("Head First Java"));
        bookList.add(new Book("Head First JavaScript"));
        bookList.add(new Book("Head First HTML"));
        bookList.add(new Book("C- CookBook"));
        return bookList;

    }

    private ArrayList<Movie> prepareMovieList(){

        ArrayList<Movie> movieList = new ArrayList<Movie>();
        movieList.add(new Movie("DDLJ","xyz",1992,9));
        movieList.add(new Movie("lagaan","abc",2007,10));
        return movieList;
    }
}
